package MideatorPattern.demo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author： pang-yun
 * @date： 2022-01-05 16:49
 * 功能目的 ：用于  具体中介者
 */

public class Mediator extends IMediator {

    private Mediator() {
    }

    private static Mediator instance = new Mediator();

    public static Mediator getInstance() {
        return instance;
    }


    private List<IColleague> list = new ArrayList<>();

    @Override
    public void register(IColleague iColleague) {
        if (!list.contains(iColleague)){
            list.add(iColleague);
        }
    }

    @Override
    public void relay(IColleague iColleague) {
        list.stream().filter(iColleague1 -> iColleague!=iColleague1)
                .forEach(IColleague::receive);
    }
}
